package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.dto.product.ProductSearchDto;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.product.ProductVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name="商品管理模块")
@RequestMapping("/admin/product/product")
public class ProductController {
    @Resource
    ProductService productService;
    @Operation(summary = "商品上下架")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable("id")Long id,
                                    @PathVariable("status")Integer status){
        productService.updateStatusById(id,status);
        return Result.ok(null);
    }
    @Operation(summary = "审核商品")
    @GetMapping("updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable("id")Long id,
                                    @PathVariable("auditStatus")Integer auditStatus){
        productService.updateAuditStatusById(id,auditStatus);
        return Result.ok(null);
    }

    @Operation(summary = "更新商品")
    @PutMapping
    public Result updateById(@RequestBody ProductDto productDto){
        productService.updateById(productDto);
        return Result.ok(null);
    }
    @Operation(summary = "根据id查询要修改的商品详情")
    @GetMapping("{id}")
    public Result<ProductDto> getById(@PathVariable("id")Long id){
        ProductDto productDto = productService.getById(id);
        return Result.ok(productDto);
    }
    @Operation(summary = "删除商品")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id")Long id){
        productService.deleteById(id);
        return Result.ok(null);
    }
    @Operation(summary = "新增商品")
    @PostMapping
    public Result save(@RequestBody ProductDto productDto){
        productService.save(productDto);
        return Result.ok(null);
    }

    /*
        1、接收前端提交的查询条件
            1/10?brandId=&category1Id=&category2Id=&category3Id=
            创建DTO接收请求参数
        2、根据条件查询分页数据

        3、前端得到数据后展示
            轮播图、商品名称、品牌名称、123级分类标题、计量单位、状态 审核状态、id
            - 需要多表联查
            - 自定义bean VO封装数据


     */
    @Operation(summary = "条件分页查询商品列表")
    @GetMapping("{pageNum}/{pageSize}")
    public Result<PageInfo<ProductVo>> page(@PathVariable("pageNum")Integer pageNum,
                                            @PathVariable("pageSize")Integer pageSize,
                                            ProductSearchDto searchDto){
        PageInfo<ProductVo> pageInfo = productService.page(pageNum,pageSize,searchDto);
        return Result.ok(pageInfo);
    }

}
